var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2UIManager = require("UIManager");
var $2BaseUIView = require("BaseUIView");
var $2GameUser = require("GameUser");
var $2UIPLoading = require("UIPLoading");
var $2PlatformMgr = require("PlatformMgr");
var $2UIHelp = require("UIHelp");
var $2GameConfig = require("GameConfig");
var $2levelconfig = require("levelconfig");
var $2AudioManager = require("AudioManager");
var $2Platformconf = require("Platformconf");
var $2MiniPlatform = require("MiniPlatform");
var $2BundleManager = require("BundleManager");
var $2UIPSetting = require("UIPSetting");
var $2UIPskin = require("UIPskin");
var $2UIPtili = require("UIPtili");
var $2UIPrank = require("UIPrank");
var $2TimeManager = require("TimeManager");
var $2UIPfree = require("UIPfree");
var $2gameBefore = require("gameBefore");
var $2UISidebar = require("UISidebar");
var $2UIAddDesk = require("UIAddDesk");
var $2UICollect = require("UICollect");
var $2Globe = require("Globe");
var $2level_ui = require("level_ui");
var $2EventCenter = require("EventCenter");
var $2EventDefine = require("EventDefine");

var Adv_skd=require("./Adv_skd")

var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_UIVMain = /* */function (_s$default5) {
  function _ctor() {
    var _this136;
    babel_classCallCheck(this, _ctor);
    _this136 = _callSuper(this, _ctor, arguments);
    _this136.mapNode = null;
    _this136.btnMaterial = [];
    _this136.btn_YXQND = null;
    _this136.spine = null;
    _this136.spinedata = [];
    _this136.btngame_3 = null;
    _this136.btn_desk = null;
    _this136.btn_sidebar = null;
    _this136.btn_collect = null;
    _this136.leftBtnView = null;
    _this136.rightBtnView = null;
    _this136.btn_tili = null;
    _this136.levelUI = null;
    _this136.isHome = true;
    _this136.currlv = 0;
    _this136.hero = ["hero1", "hero2", "hero3"];
    _this136.range = 0;
    _this136.yxqBtn = null;
    return _this136;
  }
  babel_inherits(_ctor, _s$default5);
  return babel_createClass(_ctor, [{
    key: "setContent",
    value: function setContent(e) {
      var t;
      this.isHome = e;
      this.node.getChildByName("content").active = e;
      if ($2Platformconf.default.PlatformType == $2Platformconf.ePlatformType.WXGame) {
        if (e) {
          this.showYXQ();
        } else {
          this.hideYXQ();
        }
      }
      e && (null === (t = this.levelUI) || undefined === t || t.exit());
    }
  }, {
    key: "onLoad",
    value: function onLoad() {
      Adv_skd.default.instance.hideBannerAd()
      Adv_skd.default.instance.hideGridAdLeftOne()
      Adv_skd.default.instance.hideGridAdRightOne()
      Adv_skd.default.instance.showGridAdLeftOne()
      Adv_skd.default.instance.showGridAdRightOne()
      console.log('显示首页')

      babel_get(babel_getPrototypeOf(_ctor.prototype), "onLoad", this).call(this);
      cc.director.getPhysicsManager().enabled = true;
      this.checkExtFun();
      cc.macro.ENABLE_MULTI_TOUCH = false;
      this.syncBtnViewAdapt();
      cc.game.setFrameRate(61);
      var e = this.mapNode.parent.children[this.mapNode.getSiblingIndex() + 1];
      this.levelUI = e.getComponent($2level_ui.default);
      this.syncDesktopBtnState();
      this.syncCollectBtnState();
    }
  }, {
    key: "syncDesktopBtnState",
    value: function syncDesktopBtnState() {
      if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) {
        if (cc.sys.os == cc.sys.OS_IOS) {
          var _e76 = $2GameUser.default.getInstance().getDesktopDailyRewardClaimState();
          this.btn_desk.active = !_e76;
        } else {
          var _e77 = $2GameUser.default.getInstance().getDesktopDailyRewardClaimState();
          this.btn_desk.active = !_e77;
        }
      } else {
        this.btn_desk.active = false;
      }
    }
  }, {
    key: "syncCollectBtnState",
    value: function syncCollectBtnState() {
      if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) {
        var _e78 = $2GameUser.default.getInstance().getCollectionRewardClaimState();
        this.btn_collect.active = !_e78;
      } else {
        this.btn_collect.active = false;
      }
    }
  }, {
    key: "syncBtnViewAdapt",
    value: function syncBtnViewAdapt() {
      if (cc.sys.platform === cc.sys.WECHAT_GAME || cc.sys.isBrowser) {
        this.leftBtnView.y = 70;
        this.rightBtnView.y = 340;
      } else if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) {
        this.leftBtnView.y = 230, this.rightBtnView.y = 230;
      }
    }
  }, {
    key: "set_hero",
    value: function set_hero() {
      var e = $2GameUser.default.getInstance().curr_skin_spine;
      var t = parseInt(e);
      this.spine.skeletonData = this.spinedata[t];
      this.spine.setAnimation(0, "idle", true);
    }
  }, {
    key: "onShow",
    value: function onShow() {
      var _this137 = this;
      babel_get(babel_getPrototypeOf(_ctor.prototype), "onShow", this).call(this);
      $2UIManager.UIManager.getInstance().hideUI($2UIPLoading.default);
      $2AudioManager.AudioManager.getInstance().stopMusic();
      $2AudioManager.AudioManager.getInstance().playBGM("bgm");
      this.set_hero();
      var e = new Date().getTime();
      var t = $2GameUser.default.getInstance().lastEndTime;
      if (0 != t) {
        var _n68 = e - t;
        var _o129 = _n68 / 1e3;
        console.log("t3", _n68);
        console.log("t4", _o129);
        var _i34 = Math.floor(_o129 / 600);
        if ($2GameUser.default.getInstance().tili < 5) {
          $2GameUser.default.getInstance().tili += _i34;
          $2GameUser.default.getInstance().tili > 5 && ($2GameUser.default.getInstance().tili = 5);
        }
      }
      $2EventCenter.default.postEvent($2EventDefine.default.GAME_TILI_INFO_UPDATE);
      var n = $2TimeManager.TimeManager.getInstance().get_MonthAndDay();
      var o = $2GameUser.default.getInstance().lastday;
      var s = $2GameUser.default.getInstance().lastMonth;
      var l = new Date().getMonth() + "月";
      if (n != o) {
        $2GameUser.default.getInstance().lastday = n;
        $2GameUser.default.getInstance().PassLevelNum_day = 0;
        var _e79 = $2TimeManager.TimeManager.getInstance().getWeekTH();
        if (_e79 != $2GameUser.default.getInstance().dijizhou) {
          $2GameUser.default.getInstance().PassLevelNum_week = 0;
          $2GameUser.default.getInstance().dijizhou = _e79;
        }
        if (l != s) {
          $2GameUser.default.getInstance().lastMonth = l;
          $2GameUser.default.getInstance().PassLevelNum_month = 0;
        }
        $2GameUser.default.getInstance().setUnlocktili("0", false);
        $2GameUser.default.getInstance().setUnlocktili("6", false);
        $2GameUser.default.getInstance().setUnlocktili("5", false);
        $2GameUser.default.getInstance().setUnlocktili("get0", false);
        $2GameUser.default.getInstance().setUnlocktili("get6", false);
        $2GameUser.default.getInstance().setUnlocktili("get5", false);
        $2GameUser.default.getInstance().setUnlocktili("1", false);
        $2GameUser.default.getInstance().setUnlocktili("2", false);
        $2GameUser.default.getInstance().setUnlocktili("3", false);
        $2GameUser.default.getInstance().setUnlocktili("get1", false);
        $2GameUser.default.getInstance().setUnlocktili("get2", false);
        $2GameUser.default.getInstance().setUnlocktili("get3", false);
      }
      if ($2Platformconf.default.PlatformType == $2Platformconf.ePlatformType.WXGame) {
        var _e80 = this.convertToWXRect(this.btn_YXQND);
        this.createYXQBtn(_e80);
      }
      this.schedule(function () {
        _this137.initred();
      }, 1);
    }
  }, {
    key: "initred",
    value: function initred() {
      var e = !$2GameUser.default.getInstance().getUnlocktili("get0") && $2GameUser.default.getInstance().getUnlocktili("0");
      var t = !$2GameUser.default.getInstance().getUnlocktili("get1") && $2GameUser.default.getInstance().getUnlocktili("1");
      var n = !$2GameUser.default.getInstance().getUnlocktili("get2") && $2GameUser.default.getInstance().getUnlocktili("2");
      var o = !$2GameUser.default.getInstance().getUnlocktili("get3") && $2GameUser.default.getInstance().getUnlocktili("3");
      var i = !$2GameUser.default.getInstance().getUnlocktili("get4") && $2GameUser.default.getInstance().getUnlocktili("4");
      var s = !$2GameUser.default.getInstance().getUnlocktili("get5") && $2GameUser.default.getInstance().getUnlocktili("5");
      var r = !$2GameUser.default.getInstance().getUnlocktili("get6") && $2GameUser.default.getInstance().getUnlocktili("6");
      this.btn_tili.getChildByName("red").active = !!(e || t || n || o || i || s || r);
    }
  }, {
    key: "convertToWXRect",
    value: function convertToWXRect(e) {
      var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
      var n = {};
      console.log("微信获取尺寸");
      if (window.wx) {
        var _o130 = window.canvas.width / cc.winSize.width;
        var _i35 = window.canvas.height / cc.winSize.height;
        var _s13 = e.getComponent(cc.Widget);
        _s13 && _s13.updateAlignment();
        var _a23 = e.convertToWorldSpaceAR(cc.v2(0, 0));
        var _r5 = e.width * t;
        var _l4 = e.height * t;
        var _c3 = _r5 * _o130 / (window.canvas.width / window.wx.getSystemInfoSync().windowWidth);
        var _d2 = _l4 * _i35 / (window.canvas.height / window.wx.getSystemInfoSync().windowHeight);
        var _h2 = window.wx.getSystemInfoSync().windowWidth / (cc.winSize.width / _a23.x) - _c3 / 2;
        var _u2 = window.wx.getSystemInfoSync().windowHeight / (cc.winSize.height / (cc.winSize.height - _a23.y)) - _d2 / 2;
        n.left = _h2;
        n.top = _u2;
        n.width = _c3;
        n.height = _d2;
        return n;
      }
      return n;
    }
  }, {
    key: "onEnable",
    value: function onEnable() {
      babel_get(babel_getPrototypeOf(_ctor.prototype), "onEnable", this).call(this);
      cc.director.isPaused() && cc.director.resume();
      this.init_btn();
      $2Platformconf.default.PlatformType == $2Platformconf.ePlatformType.WXGame && wx.onAddToFavorites(function () {
        console.log("onAddToFavorites");
        $2GameUser.default.getInstance().setUnlocktili("2", true);
        $2UIManager.UIManager.getInstance().getUI($2UIPfree.default).flash_2();
      });
      if ($2GameUser.default.getInstance().IsNewPlayer) {
        $2GameUser.default.getInstance().tili -= 1;
        $2EventCenter.default.postEvent($2EventDefine.default.GAME_TILI_INFO_UPDATE);
        this.setContent(false);
        this.initGame();
      }
    }
  }, {
    key: "onDisable",
    value: function onDisable() {
      this.mapNode.destroyAllChildren();
      var e = new Date().getTime();
      $2GameUser.default.getInstance().lastEndTime = e;
      console.log("onDisable  t:", e);
      babel_get(babel_getPrototypeOf(_ctor.prototype), "onDisable", this).call(this);
    }
  }, {
    key: "showBanner",
    value: function showBanner() {
      $2Platformconf.default.PlatformType != $2Platformconf.ePlatformType.VIVOGame && $2Platformconf.default.PlatformType != $2Platformconf.ePlatformType.OPPOGame || $2PlatformMgr.default.Instance().bannerShow(0);
    }
  }, {
    key: "hideBanner",
    value: function hideBanner() {
      $2Platformconf.default.PlatformType != $2Platformconf.ePlatformType.VIVOGame && $2Platformconf.default.PlatformType != $2Platformconf.ePlatformType.OPPOGame && $2Platformconf.default.PlatformType != $2Platformconf.ePlatformType.ZFBGame || $2PlatformMgr.default.Instance().bannerHide(0);
    }
  }, {
    key: "initGame",
    value: function initGame() {
      var _this138 = this;
      $2GameUser.default.getInstance().playnum++;
      cc.director.isPaused() && cc.director.resume();
      cc.Canvas.instance.node.getComponent($2gameBefore.default).BannerHide();
      $2UIHelp.UIHelp.showTip("体力-1");
      $2MiniPlatform.default.Instance.recorderStop();
      $2MiniPlatform.default.Instance.recorderStart();
      this.mapNode.destroyAllChildren();
      var e = $2GameConfig.default.getInstance().getConfig($2levelconfig.default);
      var t = $2GameUser.default.getInstance().currlevelName;
      var n = e.getlevelByName(t);
      console.log("关卡名", n.prefabName);
      var o = n.levelsBundleName;
      var i = $2BundleManager.default.getInstance().levelsBundle;
      (i = "levels" == o ? $2BundleManager.default.getInstance().levelsBundle : $2BundleManager.default.getInstance().levelsBundles[parseInt(o)]).load(n.prefabName + "/prefab/" + n.prefabName, cc.Prefab, function (e, t) {
        var n;
        if (!e && cc.isValid(_this138.mapNode, true)) {
          var _e81 = cc.instantiate(t);
          _e81.setParent(_this138.mapNode);
          _e81.setPosition(0, 0);
          null === (n = _this138.levelUI) || undefined === n || n.enter(_e81);
        } else {
          console.log("------", e);
        }
      });
    }
  }, {
    key: "click",
    value: function click(e, t) {
      var _this139 = this;
      babel_get(babel_getPrototypeOf(_ctor.prototype), "click", this).call(this, e, t);
      if ("set" == t) {
        $2Globe.default.getInstance().is_UIPsetting = true;
        $2UIManager.UIManager.getInstance().showUI($2UIPSetting.default);
      } else if ("replay" == t) {
        if ($2GameUser.default.getInstance().tili >= 1) {
          $2GameUser.default.getInstance().tili -= 1;
          $2EventCenter.default.postEvent($2EventDefine.default.GAME_TILI_INFO_UPDATE);
          this.initGame();
        } else {
          $2UIHelp.UIHelp.showTip("体力不足");
          $2UIManager.UIManager.getInstance().showUI($2UIPtili.default);
        }
      } else if ("close" == t) {
        cc.director.isPaused() && cc.director.resume();
        $2MiniPlatform.default.Instance.recorderResume();
      } else if ("btn_skin" == t) {
        $2UIManager.UIManager.getInstance().showUI($2UIPskin.default);
      } else if ("btn_rank" == t) {
        $2UIManager.UIManager.getInstance().showUI($2UIPrank.default);
      } else if ("btn_tili" == t) {
        $2UIManager.UIManager.getInstance().showUI($2UIPfree.default);
        console.log("免费体力");
      } else if ("gamestart" == t) {
        if ($2GameUser.default.getInstance().tili >= 1) {
          $2GameUser.default.getInstance().tili -= 1;
          $2EventCenter.default.postEvent($2EventDefine.default.GAME_TILI_INFO_UPDATE);
          this.setContent(false);
          $2GameUser.default.getInstance().currlevelName = "game_2";
          this.initGame();
        } else {
          $2UIHelp.UIHelp.showTip("体力不足");
          $2UIManager.UIManager.getInstance().showUI($2UIPtili.default);
        }
      } else if ("game_3" == t) {
        if ($2GameUser.default.getInstance().getUnlockLevel("game_3")) {
          if ($2GameUser.default.getInstance().tili >= 1) {
            $2GameUser.default.getInstance().tili -= 1;
            $2EventCenter.default.postEvent($2EventDefine.default.GAME_TILI_INFO_UPDATE);
            this.setContent(false);
            $2GameUser.default.getInstance().currlevelName = "game_3";
            this.initGame();
          } else {
            $2UIHelp.UIHelp.showTip("体力不足");
            $2UIManager.UIManager.getInstance().showUI($2UIPtili.default);
          }
        } else {
          this.levelPlayAD(function () {
            $2GameUser.default.getInstance().setUnlockLevel("game_3", true);
            _this139.btngame_3.getChildByName("video").active = false;
            _this139.btngame_3.getChildByName("name").x = 0;
            if ($2GameUser.default.getInstance().tili >= 1) {
              $2GameUser.default.getInstance().tili -= 1;
              $2EventCenter.default.postEvent($2EventDefine.default.GAME_TILI_INFO_UPDATE);
              _this139.setContent(false);
              $2GameUser.default.getInstance().currlevelName = "game_3";
              _this139.initGame();
            } else {
              $2UIHelp.UIHelp.showTip("体力不足");
              $2UIManager.UIManager.getInstance().showUI($2UIPtili.default);
            }
          });
        }
      } else if ("btn_sidebar" == t) {
        this.onSideBar();
      } else if ("btn_desk" == t) {
        this.onAddDesk();
      } else {
        "btn_collect" == t && this.onCollect();
      }
    }
  }, {
    key: "levelPlayAD",
    value: function levelPlayAD(e, t) {
      console.log('看广告',e,t)
      $2PlatformMgr.default.Instance().play_AD(function (n) {
        if (true === n) {
          e(n);
        } else if (1005 == n || 1006 == n || 1007 == n || 1004 == n) {
          $2UIHelp.UIHelp.showTip("获取广告失败！");
          t && t();
        } else {
          $2UIHelp.UIHelp.showTip("观看完整广告才可以获得奖励！");
          t && t();
        }
      }, {
        videoid: 1,
        origin: "levelPlayAD"
      });
    }
  }, {
    key: "createYXQBtn",
    value: function createYXQBtn(e) {
      if (null == window.wx) {
        return;
      }
      var t = window.wx.getSystemInfoSync;
      var n = t.screenWidth;
      var o = t.screenHeight;
      console.log("1111111", n, o);
      this.yxqBtn = window.wx.createGameClubButton({
        type: "image",
        image: "https://oppomini.eqmobi.com/stonesh/share/wxtm.png",
        style: {
          left: e.left,
          top: e.top,
          width: e.width,
          height: e.height
        },
        openlink: ""
      });
      this.yxqBtn.onTap(function () {
        console.log("游戏圈");
        $2GameUser.default.getInstance().setUnlocktili("5", true);
      });
    }
  }, {
    key: "showYXQ",
    value: function showYXQ() {
      null != this.yxqBtn && this.yxqBtn.show();
    }
  }, {
    key: "hideYXQ",
    value: function hideYXQ() {
      null != this.yxqBtn && this.yxqBtn.hide();
    }
  }, {
    key: "init_btn",
    value: function init_btn() {
      var e = $2GameUser.default.getInstance().getUnlockLevel("game_3");
      this.btngame_3.getChildByName("video").active = !e;
      this.btngame_3.getChildByName("name").x = e ? 0 : 30;
    }
  }, {
    key: "onAddDesk",
    value: function onAddDesk() {
      $2UIManager.UIManager.getInstance().showUI($2UIAddDesk.default);
    }
  }, {
    key: "onSideBar",
    value: function onSideBar() {
      $2UIManager.UIManager.getInstance().showUI($2UISidebar.default);
    }
  }, {
    key: "onCollect",
    value: function onCollect() {
      $2UIManager.UIManager.getInstance().showUI($2UICollect.default);
    }
  }, {
    key: "checkExtFun",
    value: function checkExtFun() {}
  }]);
}($2BaseUIView.default);
def_UIVMain.className = "UIVMain";
cc__decorate([ccp_property(cc.Node)], def_UIVMain.prototype, "mapNode", undefined);
cc__decorate([ccp_property(cc.Material)], def_UIVMain.prototype, "btnMaterial", undefined);
cc__decorate([ccp_property(cc.Node)], def_UIVMain.prototype, "btn_YXQND", undefined);
cc__decorate([ccp_property(sp.Skeleton)], def_UIVMain.prototype, "spine", undefined);
cc__decorate([ccp_property(sp.SkeletonData)], def_UIVMain.prototype, "spinedata", undefined);
cc__decorate([ccp_property(cc.Node)], def_UIVMain.prototype, "btngame_3", undefined);
cc__decorate([ccp_property(cc.Node)], def_UIVMain.prototype, "btn_desk", undefined);
cc__decorate([ccp_property(cc.Node)], def_UIVMain.prototype, "btn_sidebar", undefined);
cc__decorate([ccp_property(cc.Node)], def_UIVMain.prototype, "btn_collect", undefined);
cc__decorate([ccp_property(cc.Node)], def_UIVMain.prototype, "leftBtnView", undefined);
cc__decorate([ccp_property(cc.Node)], def_UIVMain.prototype, "rightBtnView", undefined);
cc__decorate([ccp_property(cc.Node)], def_UIVMain.prototype, "btn_tili", undefined);
def_UIVMain = cc__decorate([ccp_ccclass], def_UIVMain);
exports.default = def_UIVMain;